
/**
 * Jun 3, 2010
 * Jiadong Zhu
 * jiadong.zhu@exigenservices.com
 */

package taihootech.qa.th.loader;

import java.io.File;
import java.util.ArrayList;

public class FilesLoader extends Loader {
	
	protected static String PACKAGE = "com.taihootech.qa.testcases";
	
	private String ext = "";
	private ArrayList<File> files = null;

	public FilesLoader(ISuiteLoader iloader) {
		super(iloader);
		this.ext = ".class";
		this.files = new ArrayList<File>();
		this.iloader = iloader;
	}///:~

	public void runSuite(Object obj) {
		String pakcage = "com.taihootech.qa.testcases";
		if(obj instanceof String)
			pakcage = obj.toString(); 
		pakcage = pakcage.replace('.', '/');
		File dir = new File(pakcage);
		getFiles(dir);
		
		this.iloader.runSuite(files);
	}///:~
	
	private void getFiles(File dir) {
		if (!dir.exists())
			return;
		
		if(dir.isDirectory()) {
			String[] sub_files = dir.list();
			for(String sub_file : sub_files) {
				getFiles(new File(dir, sub_file));
			}
		} else {
			if(dir.getName().endsWith(ext))
				files.add(dir);
		}
	}///:~

}///:~ FilesLoader Ends


